﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Weight.Controls
{
    public partial class LYFLoading : UserControl
    {
        public LYFLoading()
        {
            this.Visible = false;
            InitializeComponent();
            //设置Style支持透明背景色
            webBrowser1.ScriptErrorsSuppressed = true; //禁用错误脚本提示
            webBrowser1.IsWebBrowserContextMenuEnabled = false; // 禁用右键菜单
            webBrowser1.WebBrowserShortcutsEnabled = false; //禁用快捷键
            webBrowser1.AllowWebBrowserDrop = false; // 禁止文件拖动

  
        }

        /// <summary>
        /// 展示进度条
        /// </summary>
        public void ShowLoading()
        {
            webBrowser1.Navigate(Application.StartupPath + @"\Html\loading\loading.html");
            webBrowser1.Navigated += WebBrowserNavigatedEventHandler;
            webBrowser1.DocumentCompleted += WebBrowserDocumentCompletedEventHandler;
            webBrowser1.Document.Window.Error += new HtmlElementErrorEventHandler(Window_Error);
            webBrowser1.NewWindow += CancelEventHandler;
            this.Visible = true;
        }

        public void HideLoading()
        {
            this.Visible = false;
        }

        //禁用新窗口打开
        public void CancelEventHandler(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void Window_Error(object sender, HtmlElementErrorEventArgs e)
        {
            e.Handled = true;
        }

        //后发生
        public void WebBrowserDocumentCompletedEventHandler(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser1.Document.BackColor = System.Drawing.Color.Transparent;
        }

        //先发生
        public void WebBrowserNavigatedEventHandler(object sender, WebBrowserNavigatedEventArgs e)
        {
        }
    }
}
